package com.wifi.a007;


import android.content.ComponentName;
import android.content.Context;
import android.content.res.Configuration;
import android.net.wifi.ScanResult;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.wifi.a007.wifiFragment.NetScan;


public class MainActivity extends AppCompatActivity  implements  View.OnClickListener {
    private  Button gateway;

    private LinearLayout newsLayout;
    private LinearLayout readLayout;
    private LinearLayout videoLayout;
    private LinearLayout lampLayout;
    private LinearLayout pcLayout;


    private Fragment[] mFragments;
    private FragmentManager fragmentManager;
    private FragmentTransaction fragmentTransaction;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



        setContentView(R.layout.activity_main);
        //这是底部的按钮e

        ViewName.mContext=this;
       // ViewName.init(R.layout.activity_main,(View)MainActivity.this);

        init();



    }

    private void init(){

        newsLayout = (LinearLayout) findViewById(R.id.wifi_net_layout);
        readLayout = (LinearLayout) findViewById(R.id.bottom_webView_layout);
        videoLayout = (LinearLayout) findViewById(R.id.bottom_localnet_layout);
        lampLayout = (LinearLayout) findViewById(R.id.bottom_lamp_layout);
        pcLayout = (LinearLayout) findViewById(R.id.bottom_pc_layout);
        ViewName.listMenu =(Button)findViewById(R.id.html_menu);
        ViewName.listMenu.setOnClickListener(ClickFunction.initClick());



        newsLayout.setOnClickListener(this);
        readLayout.setOnClickListener(this);
        videoLayout.setOnClickListener(this);
        lampLayout.setOnClickListener(this);
        pcLayout.setOnClickListener(this);
        newsLayout.setSelected(true);



        mFragments = new Fragment[5];
        fragmentManager = getSupportFragmentManager();
        mFragments[0] = fragmentManager.findFragmentById(R.id.wifiNet);
        mFragments[1] = fragmentManager.findFragmentById(R.id.webView);
        mFragments[2] = fragmentManager.findFragmentById(R.id.localNet);
        mFragments[3] = fragmentManager.findFragmentById(R.id.lamp);
        mFragments[4] = fragmentManager.findFragmentById(R.id.pc);
        fragmentTransaction = fragmentManager.beginTransaction()
                .hide(mFragments[0]).hide(mFragments[1]).hide(mFragments[2]).hide(mFragments[3]).hide(mFragments[4]);
        fragmentTransaction.show(mFragments[0]).commit();


        ///

        ViewName.mainHandler=handler;

    }

    @Override
    public void onClick(View v) {
        fragmentTransaction = fragmentManager.beginTransaction()
                .hide(mFragments[0]).hide(mFragments[1]).hide(mFragments[2]).hide(mFragments[3]).hide(mFragments[4]);

        switch (v.getId()) {
            case R.id.wifi_net_layout:
                this.newsLayout.setSelected(true);
                this.readLayout.setSelected(false);
                this.videoLayout.setSelected(false);
                this.lampLayout.setSelected(false);
                this.pcLayout.setSelected(false);
                fragmentTransaction.show(mFragments[0]).commit();
                break;
            case R.id.bottom_webView_layout:
                this.newsLayout.setSelected(false);
                this.readLayout.setSelected(true);
                this.videoLayout.setSelected(false);
                this.lampLayout.setSelected(false);
                this.pcLayout.setSelected(false);
                fragmentTransaction.show(mFragments[1]).commit();
                break;
            case R.id.bottom_localnet_layout:
                this.newsLayout.setSelected(false);
                this.readLayout.setSelected(false);
                this.videoLayout.setSelected(true);
                this.lampLayout.setSelected(false);
                this.pcLayout.setSelected(false);
                fragmentTransaction.show(mFragments[2]).commit();
                break;
            case R.id.bottom_lamp_layout:
                this.newsLayout.setSelected(false);
                this.readLayout.setSelected(false);
                this.videoLayout.setSelected(false);
                this.lampLayout.setSelected(true);
                this.pcLayout.setSelected(false);
                fragmentTransaction.show(mFragments[3]).commit();
                break;
            case R.id.bottom_pc_layout:
                this.newsLayout.setSelected(false);
                this.readLayout.setSelected(false);
                this.videoLayout.setSelected(false);
                this.lampLayout.setSelected(false);
                this.pcLayout.setSelected(true);
                fragmentTransaction.show(mFragments[4]).commit();
                break;





            default:

        }
    }

    private static Handler handler=new Handler() {

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {


                default:

            }
        }



    };


    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        //控制activity的configuration属性决定屏幕变化不会被刷新
        //重写这个相应屏幕变化

    }


}
